//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.tuiofx.internal.gesture;

import javafx.geometry.Point2D;
import javafx.scene.Node;
import org.tuiofx.Configuration;
import org.tuiofx.internal.base.TuioFXCanvas;

public class GestureTracker extends GestureRecognizer {
    private CursorTracker gestureTracker;

    public GestureTracker(Node targetNode, Configuration config) {
        super(targetNode, config);
        this.gestureTracker = new CursorTracker(targetNode.getScene());
    }

    public void touchesBegan(TuioTouchPoint touchPoint) {
        this.gestureTracker.addTouchPoint(touchPoint.getSessionID(), touchPoint.getSceneX(), touchPoint.getSceneY());
        if (!this.getTargetNode().equals(this.getTargetNode().getScene().getRoot()) && !(this.getTargetNode().getParent() instanceof TuioFXCanvas)) {
            Point2D centroid = this.getCentroid();
            if (!Double.isNaN(centroid.getX()) || !Double.isNaN(centroid.getY())) {
                this.gestureTracker.updateCentroid(this.getCentroid());
            }
        }

    }

    public void touchesMove(TuioTouchPoint touchPoint) {
        this.gestureTracker.updateTouchPoint(touchPoint.getSessionID(), touchPoint.getSceneX(), touchPoint.getSceneY());
        if (!this.getTargetNode().equals(this.getTargetNode().getScene().getRoot()) && !(this.getTargetNode().getParent() instanceof TuioFXCanvas)) {
            Point2D centroid = this.getCentroid();
            if (!Double.isNaN(centroid.getX()) || !Double.isNaN(centroid.getY())) {
                this.gestureTracker.updateCentroid(this.getCentroid());
            }
        }

    }

    public void touchesEnd(TuioTouchPoint touchPoint) {
        if (!this.getTargetNode().equals(this.getTargetNode().getScene().getRoot()) && !(this.getTargetNode().getParent() instanceof TuioFXCanvas)) {
            Point2D centroidPoint = this.getCentroid();
            if (!Double.isNaN(centroidPoint.getX()) && !Double.isNaN(centroidPoint.getY())) {
                this.gestureTracker.updateCentroid(centroidPoint);
            } else {
                this.gestureTracker.removeCentroid();
            }
        }

        this.gestureTracker.removeTouchPoint(touchPoint.getSessionID());
    }
}
